Make -s rename duplicate generated shortnames.
static FILE *file_in;
static FILE *file_out;
+static void *mkshort_handle;
static char *psn;
#define MYNAME "CSV"
rd_init(const char *fname, const char *args)
{
file_in = fopen(fname, "r");
+ mkshort_handle = mkshort_new_handle();
+
if (file_in == NULL) {
fatal(MYNAME ": Cannot open %s for reading\n", fname);
}
static void
rd_deinit(void)
{
+ mkshort_del_handle(mkshort_handle);
fclose(file_in);
}
wr_init(const char *fname, const char *args)
{
file_out = fopen(fname, "w");
+
psn = get_option(args, "prefer_shortname");
if (file_out == NULL) {
/* We'll make up our own shortname. */
if (wpt_tmp->description) {
- wpt_tmp->shortname = mkshort(wpt_tmp->description);
+ wpt_tmp->shortname = mkshort(mkshort_handle, wpt_tmp->description);
waypt_add(wpt_tmp);
}
#define EXCEL_TO_TIMET(a) ((a - 25569.0) * 86400.0)
#define TIMET_TO_EXCEL(a) ((a / 86400.0) + 25569.0)
+static void *mkshort_handle;
+
/*********************************************************************/
/* csv_stringclean() - remove any unwanted characters from string. */
/* returns copy of string. */
queue *elem, *tmp;
if (wpt->shortname) {
- anyname = xstrdup(wpt->shortname);
+ anyname = xstrdup(mkshort(mkshort_handle, wpt->shortname));
} else
if (wpt->description) {
- anyname = xstrdup(wpt->description);
+ anyname = xstrdup(mkshort(mkshort_handle, wpt->description));
} else
if (wpt->notes) {
anyname = xstrdup(wpt->notes);
anyname = xstrdup("");
if ((anyname) && (global_opts.synthesize_shortnames)) {
- anyname = mkshort(anyname);
+ anyname = mkshort(mkshort_handle, anyname);
}
if ((! wpt->shortname) || (global_opts.synthesize_shortnames)) {
if (wpt->description) {
if (global_opts.synthesize_shortnames)
- shortname = mkshort(wpt->description);
+ shortname = mkshort(mkshort_handle, wpt->description);
else
shortname = csv_stringclean(wpt->description, xcsv_file.badchars);
} else {
{
queue *elem, *tmp;
ogue_t *ogp;
+ mkshort_handle = mkshort_new_handle();
/* output prologue lines, if any. */
QUEUE_FOR_EACH(&xcsv_file.prologue, elem, tmp) {
ogp = (ogue_t *) elem;
fprintf (xcsv_file.xcsvfp, "%s%s", ogp->val, xcsv_file.record_delimiter);
}
-
waypt_disp_all(xcsv_waypt_pr);
/* output epilogue lines, if any. */
ogp = (ogue_t *) elem;
fprintf (xcsv_file.xcsvfp, "%s%s", ogp->val, xcsv_file.record_delimiter);
}
+ mkshort_del_handle(mkshort_handle);
}
void route_add_wpt(route_head *rte, waypoint *wpt);
void route_add_head(route_head *rte);
-char *mkshort (const char *);
-void setshort_length(int n);
-void setshort_badchars(const char *);
-void setshort_mustupper(int n);
-void setshort_whitespace_ok(int n);
+/*
+ * All shortname functions take a shortname handle as the first arg.
+ * This is an opaque pointer. Callers must not fondle the contents of it.
+ */
+char *mkshort (void *, const char *);
+void *mkshort_new_handle(void);
+void setshort_length(void *, int n);
+void setshort_badchars(void *, const char *);
+void setshort_mustupper(void *, int n);
+void setshort_whitespace_ok(void *, int n);
typedef struct ff_vecs {
ff_init rd_init;
static FILE *file_in;
static FILE *file_out;
+static void *mkshort_handle;
#define MYNAME "DNA"
rd_init(const char *fname, const char *args)
{
file_in = fopen(fname, "r");
+ mkshort_handle = mkshort_new_handle();
+
if (file_in == NULL) {
fatal(MYNAME ": Cannot open %s for reading\n", fname);
}
static void
rd_deinit(void)
{
+ mkshort_del_handle(mkshort_handle);
fclose(file_in);
}
wr_init(const char *fname, const char *args)
{
file_out = fopen(fname, "w");
+
if (file_out == NULL) {
fatal(MYNAME ": Cannot open %s for writing\n", fname);
}
wpt_tmp->creation_time = time(NULL);
/* We'll make up our own shortname. */
- wpt_tmp->shortname = mkshort(wpt_tmp->description);
+ wpt_tmp->shortname = mkshort(mkshort_handle, wpt_tmp->description);
waypt_add(wpt_tmp);
#define MYNAME "GARMIN"
static const char *portname;
+static void *mkshort_handle;
static void
rw_init(const char *fname, const char *opts)
{
+ if (!mkshort_handle)
+ mkshort_handle = mkshort_new_handle();
+
if (global_opts.debug_level > 0) {
GPS_Enable_Warning();
GPS_Enable_User();
break;
}
- setshort_length(short_length);
- setshort_mustupper(1);
+ setshort_length(mkshort_handle, short_length);
+ setshort_mustupper(mkshort_handle, 1);
QUEUE_FOR_EACH(&waypt_head, elem, tmp) {
waypoint *wpt;
char *ident;
if(wpt->notes) src = wpt->notes;
ident = global_opts.synthesize_shortnames ?
- mkshort(src) :
+ mkshort(mkshort_handle, src) :
wpt->shortname;
strncpy(way[i]->ident, ident, sizeof(way[i]->ident));
way[i]->ident[sizeof(way[i]->ident)-1] = 0;
static FILE *file_in;
static FILE *file_out;
+static void *mkshort_wr_handle;
+static void *mkshort_rd_handle;
#define MYNAME "GPSDRIVE"
int i;
waypoint *wpt_tmp;
int linecount = 0;
+ mkshort_rd_handle = mkshort_new_handle();
do {
linecount++;
/* We'll make up our own shortname. */
if (wpt_tmp->description) {
- wpt_tmp->shortname = mkshort(wpt_tmp->description);
+ wpt_tmp->shortname = mkshort(mkshort_rd_handle, wpt_tmp->description);
waypt_add(wpt_tmp);
}
}
} while (!feof(file_in));
+ mkshort_del_handle(mkshort_rd_handle);
}
static void
shortname = csv_stringclean(wpt->notes, ",\"");
if ( shortname )
- shortname = mkshort(shortname);
+ shortname = mkshort(mkshort_wr_handle, shortname);
fprintf(file_out, "%s %08.5f %08.5f\n",
shortname,
static void
data_write(void)
{
+ mkshort_wr_handle = mkshort_new_handle();
+
waypt_disp_all(gpsdrive_waypt_pr);
+ mkshort_del_handle(mkshort_wr_handle);
}
ff_vecs_t gpsdrive_vecs = {
static FILE *file_in;
static FILE *file_out;
+static void *mkshort_handle;
#define MYNAME "GPSUTIL"
if (file_out == NULL) {
fatal(MYNAME ": Cannot open %s for writing\n", fname);
}
+ mkshort_handle = mkshort_new_handle();
+
}
static void
wr_deinit(void)
{
fclose(file_out);
+ mkshort_del_handle(mkshort_handle);
}
static void
fprintf(file_out, "%-8s %08.3f%c %09.3f%c %07.0f%c %-30.30s %s\n",
global_opts.synthesize_shortnames ?
- mkshort(wpt->description) : wpt->shortname,
+ mkshort(mkshort_handle, wpt->description) :
+ wpt->shortname,
fabs(lat),
lat < 0.0 ? 'S' : 'N',
fabs(lon),
static waypoint *wpt_tmp;
static FILE *fd;
static FILE *ofd;
+static void *mkshort_handle;
#define MYNAME "GPX"
#define MY_CBUF 4096
const char **avp = attrv;
char **avcp = NULL;
int attr_count = 0;
-
xml_tag *new_tag;
if ( !wpt_tmp ) {
void
gpx_wr_init(const char *fname, const char *args)
{
+ mkshort_handle = mkshort_new_handle();
ofd = fopen(fname, "w");
if (ofd == NULL) {
fatal(MYNAME ": open %s for writing\n", fname );
gpx_wr_deinit(void)
{
fclose(ofd);
+ mkshort_del_handle(mkshort_handle);
}
void
{
char *tmp_ent;
const char *oname = global_opts.synthesize_shortnames ?
- mkshort(waypointp->description) :
+ mkshort(mkshort_handle, waypointp->description) :
waypointp->shortname;
fprintf(ofd, "<wpt lat=\"%lf\" lon=\"%lf\">\n",
void
gpx_write(void)
{
- setshort_length(32);
+ setshort_length(mkshort_handle, 32);
fprintf(ofd, "<?xml version=\"1.0\"?>\n");
fprintf(ofd, "<gpx\n version=\"1.0\"\n");
static FILE *file_in;
static unsigned char *HxWFile;
+static void *mkshort_handle;
static char fOutname[256];
static void
wr_init(const char *fname, const char *args)
{
+ mkshort_handle = mkshort_new_handle();
+
HxWFile = xcalloc(GM100_WPO_FILE_SIZE, 1);
strcpy (fOutname,fname);
static void wr_deinit(void)
{
+ mkshort_del_handle(mkshort_handle);
}
if (stIn == NULL)
return NULL;
- setshort_length(sLen);
- strcpy(strTmp,mkshort(stIn));
+ setshort_length(mkshort_handle, sLen);
+ strcpy(strTmp,mkshort(mkshort_handle, stIn));
memset(strOut,' ', MAX_STRINGLEN);
strncpy (strOut,strTmp,strlen(strTmp));
static void termwrite(char *obuf, int size);
static double mag2degrees(double mag_val);
static void mag_readmsg(void);
+static void *mkshort_handle;
typedef enum {
mrs_handoff = 0,
case mm_gps315320:
case mm_map410:
icon_mapping = gps315_icon_table;
- setshort_length(6);
- setshort_mustupper(1);
+ setshort_length(mkshort_handle, 6);
+ setshort_mustupper(mkshort_handle, 1);
mag_cleanse = m315_cleanse;
break;
case mm_map330:
case mm_meridian:
case mm_sportrak:
icon_mapping = map330_icon_table;
- setshort_length(8);
- setshort_mustupper(0);
+ setshort_length(mkshort_handle, 8);
+ setshort_mustupper(mkshort_handle, 0);
mag_cleanse = m330_cleanse;
break;
default:
fstat(fileno(magfile_out), &sbuf);
is_file = S_ISREG(sbuf.st_mode);
#endif
+ mkshort_handle = mkshort_new_handle();
if (is_file) {
magfile_out = fopen(portname, "w+b");
}
isrc = waypointp->notes ? waypointp->notes : waypointp->description;
owpt = global_opts.synthesize_shortnames ?
- mkshort(isrc) : waypointp->shortname,
+ mkshort(mkshort_handle, isrc) : waypointp->shortname,
odesc = isrc ? isrc : "";
owpt = mag_cleanse(owpt);
odesc = mag_cleanse(odesc);
* Whitespace is actually legal, but since waypoint name length is
* only 8 bytes, we'll conserve them.
*/
- setshort_whitespace_ok(0);
+ setshort_whitespace_ok(mkshort_handle, 0);
waypt_disp_all(mag_waypt_pr);
}
static FILE *mapsend_file_in;
static FILE *mapsend_file_out;
+static void *mkshort_handle;
static int endianness_tested;
static int i_am_little_endian;
fprintf(stderr, "Cannot open '%s' for writing\n", fname);
exit(1);
}
+ mkshort_handle = mkshort_new_handle();
}
static void
mapsend_wr_deinit(void)
{
fclose(mapsend_file_out);
+ mkshort_del_handle(mkshort_handle);
}
static void
double flat;
static int cnt = 0;
const char *sn = global_opts.synthesize_shortnames ?
- mkshort(waypointp->description) : waypointp->shortname;
+ mkshort(mkshort_handle, waypointp->description) :
+ waypointp->shortname;
c = strlen(sn);
fwrite(&c, 1, 1, mapsend_file_out);
static FILE *mps_file_in;
static FILE *mps_file_out;
+static void *mkshort_handle;
#define MYNAME "MAPSOURCE"
if(wpt->description) src = wpt->description;
if(wpt->notes) src = wpt->notes;
ident = global_opts.synthesize_shortnames ?
- mkshort(src) :
+ mkshort(mkshort_handle, src) :
wpt->shortname;
reclen = 87 + strlen(ident) + strlen(wpt->description);
mps_write(void)
{
int short_length = 10;
+ mkshort_handle = mkshort_new_handle();
- setshort_length(short_length);
- setshort_whitespace_ok(0);
+ setshort_length(mkshort_handle, short_length);
+ setshort_whitespace_ok(mkshort_handle, 0);
fwrite(mps_hdr, sizeof(mps_hdr), 1, mps_file_out);
waypt_disp_all(mps_waypt_pr);
fwrite(mps_ftr, sizeof(mps_ftr), 1, mps_file_out);
+ mkshort_del_handle(mkshort_handle);
+
}
ff_vecs_t mps_vecs = {
static const char vowels[] = "aeiouAEIOU";
#define DEFAULT_TARGET_LEN 8
-static unsigned int target_len = DEFAULT_TARGET_LEN;
-
#define DEFAULT_BADCHARS "\"$.,'!-"
-static const char *badchars = DEFAULT_BADCHARS;
-static int mustupper = 0;
-static int whitespaceok = 1;
-static const char needmem[] =
- "mkshort: could not reallocate memory for string\n";
+/*
+ * Hash table tunings. The reality is that our hash doesn't have to be
+ * terribly complex; our strings are short (typically 8-20 bytes) and the
+ * string hash mixes things up enough that strcmp can generally bail on the
+ * first byte or two for a mismatch.
+ */
+#define PRIME 37
+
+typedef struct {
+ int mustupper;
+ int whitespaceok;
+ unsigned int target_len;
+ char *badchars;
+ int must_uniq;
+ queue namelist[PRIME];
+ int depth[PRIME];
+} mkshort_handle;
+
+typedef struct {
+ queue list;
+ char *orig_shortname;
+ int conflictctr;
+} uniq_shortname;
+
+unsigned int hash_string(const char *key)
+{
+ unsigned int hash = 0;
+ while (*key) {
+ hash = ((hash<<5) ^ (hash>>27)) ^ *key++;
+ }
+ hash = hash % PRIME;
+ return hash;
+}
+
+void *
+mkshort_new_handle()
+{
+ int i;
+ mkshort_handle *h = xcalloc(sizeof *h, 1);
+
+ for (i = 0; i < PRIME; i++)
+ QUEUE_INIT(&h->namelist[i]);
+
+ h->whitespaceok = 1;
+ h->badchars = DEFAULT_BADCHARS;
+ h->target_len = DEFAULT_TARGET_LEN;
+ h->must_uniq=1;
+
+ return h;
+}
+
+char *
+mkshort_add_to_list(mkshort_handle *h, char *name)
+{
+ queue *e, *t;
+ int hash;
+ uniq_shortname *s = xmalloc(sizeof (uniq_shortname));
+ s->orig_shortname = strdup(name);
+ hash = hash_string(name);
+
+ QUEUE_FOR_EACH(&h->namelist[hash], e, t) {
+ uniq_shortname *z = (uniq_shortname *) e;
+
+ if (0 == strcmp(z->orig_shortname, name)) {
+ int l = strlen(name);
+ int dl;
+ char tbuf[10];
+
+ z->conflictctr++;
+ dl = sprintf(tbuf, ".%d", z->conflictctr);
+ strcpy(&name[l-dl], tbuf);
+ break;
+ }
+ }
+ ENQUEUE_TAIL(&h->namelist[hash], &s->list);
+ h->depth[hash]++;
+ return name;
+}
+
+void *
+mkshort_is_unique()
+{
+}
+
+void *
+mkshort_del_handle(void *h)
+{
+ mkshort_handle *hdr = h;
+ int i;
+
+ if (hdr) {
+ for (i = 0; i < PRIME; i++) {
+ queue *e, *t, *z;
+ QUEUE_FOR_EACH(&hdr->namelist[i], e, t) {
+ uniq_shortname *s = e;
+ dequeue(e);
+ free(s->orig_shortname);
+ free(s);
+ }
+ }
+ free(hdr);
+ }
+}
/*
* This is the stuff that makes me ashamed to be a C programmer...
* strings returned by mkshort(). 0 resets to default.
*/
void
-setshort_length(int l)
+setshort_length(void *h, int l)
{
+ mkshort_handle *hdl = h;
if (l == 0) {
- target_len = DEFAULT_TARGET_LEN;
+ hdl->target_len = DEFAULT_TARGET_LEN;
} else {
- target_len = l;
+ hdl->target_len = l;
}
}
void
-setshort_whitespace_ok(int l)
+setshort_whitespace_ok(void *h, int l)
{
- whitespaceok = l;
+ mkshort_handle *hdl = h;
+ hdl->whitespaceok = l;
}
/*
* resets to default.
*/
void
-setshort_badchars(const char *s)
+setshort_badchars(void *h, const char *s)
{
+ mkshort_handle *hdl = h;
if (s == NULL) {
- badchars = DEFAULT_BADCHARS;
+ hdl->badchars = DEFAULT_BADCHARS;
} else {
- badchars = xstrdup(s);
+ hdl->badchars = xstrdup(s);
}
}
void
-setshort_mustupper(int i)
+setshort_mustupper(void *h, int i)
{
- mustupper = i;
+ mkshort_handle *hdl = h;
+ hdl->mustupper = i;
}
char *
-mkshort(const char *istring)
+mkshort(void *h, const char *istring)
{
char *ostring = xstrdup(istring);
char *nstring;
char *cp;
char *np;
int i, l, nlen, replaced;
+ mkshort_handle *hdl = h;
/*
* Whack leading "[Tt]he",
*/
- if (( strlen(ostring) > target_len + 4) &&
+ if (( strlen(ostring) > hdl->target_len + 4) &&
(strncmp(ostring, "The ", 4) == 0 ||
strncmp(ostring, "the ", 4) == 0)) {
nstring = xstrdup(ostring + 4);
free(ostring);
ostring = nstring;
- if (!whitespaceok) {
+ if (!hdl->whitespaceok) {
/*
* Eliminate Whitespace
*/
cp = ostring;
for (i=0;i<l;i++) {
if (!isspace(tstring[i])) {
- if (mustupper) {
+ if (hdl->mustupper) {
tstring[i] = toupper(tstring[i]);
}
*cp++ = tstring[i];
l = strlen (tstring);
cp = ostring;
for (i=0;i<l;i++) {
- if (strchr(badchars, tstring[i]) || !isascii(tstring[i]))
+ if (strchr(hdl->badchars, tstring[i]) || !isascii(tstring[i]))
continue;
*cp++ = tstring[i];
}
* them. If we run out of string, give up.
*/
replaced = 1;
- while (replaced && strlen(ostring) > target_len) {
+ while (replaced && strlen(ostring) > hdl->target_len) {
ostring = delete_last_vowel(2, ostring, &replaced);
}
* Now brutally truncate the resulting string, preserve trailing
* numeric data.
*/
- if ((/*i = */strlen(ostring)) > target_len) {
- strcpy(&ostring[target_len] - strlen(np), np);
+ if ((/*i = */strlen(ostring)) > hdl->target_len) {
+ strcpy(&ostring[hdl->target_len] - strlen(np), np);
}
+
+
+ if (hdl->must_uniq) {
+ return mkshort_add_to_list(hdl, ostring);
+ }
+
return ostring;
}
#define MYNAME "MXF"
+static void *mkshort_handle;
+
static void
mxf_set_style()
{
/* set up mkshort */
if (global_opts.synthesize_shortnames) {
- setshort_length(32);
- setshort_whitespace_ok(0);
- setshort_badchars(xcsv_file.badchars);
+ setshort_length(mkshort_handle, 32);
+ setshort_whitespace_ok(mkshort_handle, 0);
+ setshort_badchars(mkshort_handle, xcsv_file.badchars);
}
}
static void
mxf_wr_init(const char *fname, const char *args)
{
+ mkshort_handle = mkshort_new_handle();
+
mxf_set_style();
xcsv_file.xcsvfp = fopen(fname, "w");
#define MYNAME "OZI"
+static void *mkshort_handle;
+
+
static void
ozi_set_style()
{
/* set up mkshort */
if (global_opts.synthesize_shortnames) {
- setshort_length(32);
- setshort_whitespace_ok(0);
- setshort_badchars(xcsv_file.badchars);
+ setshort_length(mkshort_handle, 32);
+ setshort_whitespace_ok(mkshort_handle, 0);
+ setshort_badchars(mkshort_handle, xcsv_file.badchars);
}
}
{
ozi_set_style();
+ mkshort_handle = mkshort_new_handle();
+
xcsv_file.xcsvfp = fopen(fname, "w");
if (xcsv_file.xcsvfp == NULL) {
static FILE *file_in;
static FILE *file_out;
+static void *mkshort_handle;
#define MYNAME "PCX"
wr_init(const char *fname, const char *args)
{
file_out = fopen(fname, "w");
+ mkshort_handle = mkshort_new_handle();
+
if (file_out == NULL) {
fatal(MYNAME ": Cannot open %s for writing\n", fname);
}
wr_deinit(void)
{
fclose(file_out);
+ mkshort_del_handle(mkshort_handle);
}
static void
fprintf(file_out, "W %-6.6s %c%08.5f %c%011.5f %s %5d %-40.40s %5e %s\n",
global_opts.synthesize_shortnames ?
- mkshort(wpt->description) : wpt->shortname,
+ mkshort(mkshort_handle, wpt->description) :
+ wpt->shortname,
lat < 0.0 ? 'S' : 'N',
fabs(lat),
lon < 0.0 ? 'W' : 'E',
"U LAT LON DM\n"
"\n"
"H IDNT LATITUDE LONGITUDE DATE TIME ALT DESCRIPTION PROXIMITY SYMBOL ;waypts\n");
- setshort_length(6);
+ setshort_length(mkshort_handle, 6);
waypt_disp_all(gpsutil_disp);
}
static FILE *psp_file_in;
static FILE *psp_file_out;
+static FILE *mkshort_handle;
static int i_am_little_endian;
static int endianness_tested;
psp_wr_init(const char *fname, const char *args)
{
psp_file_out = fopen(fname, "wb");
+ mkshort_handle = mkshort_new_handle();
+
if (psp_file_out == NULL) {
fatal(MYNAME ": Cannot open %s for writing\n", fname);
}
static void
psp_wr_deinit(void)
{
+ mkshort_del_handle(mkshort_handle);
fclose(psp_file_out);
}
if ((! wpt->shortname) || (global_opts.synthesize_shortnames)) {
if (wpt->description) {
if (global_opts.synthesize_shortnames)
- shortname = mkshort(wpt->description);
+ shortname = mkshort(mkshort_handle, wpt->description);
else
shortname = xstrdup(wpt->description);
} else {
s = waypt_count();
if (global_opts.synthesize_shortnames) {
- setshort_length(32);
- setshort_whitespace_ok(1);
+ setshort_length(mkshort_handle, 32);
+ setshort_whitespace_ok(mkshort_handle, 1);
}
if (s > MAXPSPOUTPUTPINS) {
static FILE *file_in;
static FILE *file_out;
+static void *mkshort_handle;
#define MYNAME "GPSUTIL"
rd_init(const char *fname, const char *args)
{
file_in = fopen(fname, "r");
+ mkshort_handle = mkshort_new_handle();
+
if (file_in == NULL) {
fatal(MYNAME ": Cannot open %s for reading\n", fname);
}
rd_deinit(void)
{
fclose(file_in);
+ mkshort_del_handle(mkshort_handle);
}
static void
wr_init(const char *fname, const char *args)
{
file_out = fopen(fname, "w");
+
if (file_out == NULL) {
fatal(MYNAME ": Cannot open %s for writing\n", fname);
}
double lat,lon;
char desc[100];
char icon[100];
+ char ibuf[1024];
waypoint *wpt_tmp;
- while( fscanf(file_in, "%lf,%lf:%100[^:]:%100[^\n]",
- &lon, &lat, icon, desc) > 0) {
- wpt_tmp = xcalloc(sizeof (*wpt_tmp), 1);
+ while (fgets(ibuf, sizeof(ibuf), file_in)) {
+ if( sscanf(ibuf, "%lf,%lf:%100[^:]:%100[^\n]",
+ &lon, &lat, icon, desc)) {
+ wpt_tmp = xcalloc(sizeof (*wpt_tmp), 1);
- wpt_tmp->position.longitude.degrees = lon;
- wpt_tmp->position.latitude.degrees = lat;
- wpt_tmp->description = xstrdup(desc);
- wpt_tmp->shortname = mkshort(desc);
+ wpt_tmp->position.longitude.degrees = lon;
+ wpt_tmp->position.latitude.degrees = lat;
+ wpt_tmp->description = xstrdup(desc);
+ wpt_tmp->shortname = mkshort(mkshort_handle, desc);
- waypt_add(wpt_tmp);
+ waypt_add(wpt_tmp);
+ }
}
}
static FILE *file_in;
static FILE *file_out;
+static void *mkshort_handle;
static void
rd_init(const char *fname, const char *args)
if ((! wpt->shortname) || (global_opts.synthesize_shortnames)) {
if (wpt->description) {
if (global_opts.synthesize_shortnames)
- shortname = mkshort(wpt->description);
+ shortname = mkshort(mkshort_handle, wpt->description);
else
shortname = csv_stringclean(wpt->description, ",\"");
} else {
{
/* Short names */
if (global_opts.synthesize_shortnames) {
- setshort_length(6);
- setshort_whitespace_ok(0);
- setshort_badchars("\",");
+ mkshort_handle = mkshort_new_handle();
+ setshort_length(mkshort_handle, 6);
+ setshort_whitespace_ok(mkshort_handle, 0);
+ setshort_badchars(mkshort_handle, "\",");
}
/* Write file header */
fprintf(file_out, "Group\tsID\tsDescription\tfLat\tfLong\tfEasting\tfNorthing\tfAlt\tiColour\tiSymbol\tsHyperLink\n");
waypt_disp_all(tmpro_waypt_pr);
+ mkshort_del_handle(mkshort_handle);
}
ff_vecs_t tmpro_vecs = {
static FILE *tpg_file_in;
static FILE *tpg_file_out;
+static void *mkshort_handle;
static int i_am_little_endian;
static int endianness_tested;
tpg_wr_init(const char *fname, const char *args)
{
tpg_file_out = fopen(fname, "wb");
+ mkshort_handle = mkshort_new_handle();
+
if (tpg_file_out == NULL) {
fatal(MYNAME ": Cannot open %s for writing\n", fname);
}
if ((! wpt->shortname) || (global_opts.synthesize_shortnames)) {
if (wpt->description) {
if (global_opts.synthesize_shortnames)
- shortname = mkshort(wpt->description);
+ shortname = mkshort(mkshort_handle, wpt->description);
else
shortname = xstrdup(wpt->description);
} else {
s = waypt_count();
if (global_opts.synthesize_shortnames) {
- setshort_length(32);
- setshort_whitespace_ok(1);
+ setshort_length(mkshort_handle, 32);
+ setshort_whitespace_ok(mkshort_handle, 1);
}
if (s > MAXTPGOUTPUTPINS) {
queue waypt_head;
static unsigned int waypt_ct;
+static void *mkshort_handle;
void
waypt_init(void)
{
+ mkshort_handle = mkshort_new_handle();
QUEUE_INIT(&waypt_head);
}
printposn(&wpt->position.longitude,0);
printf("%s/%s",
global_opts.synthesize_shortnames ?
- mkshort(wpt->description) : wpt->shortname,
- wpt->description);
+ mkshort(mkshort_handle, wpt->description) :
+ wpt->shortname,
+ wpt->description);
if (wpt->position.altitude.altitude_meters != unknown_alt)
printf(" %f", wpt->position.altitude.altitude_meters);
printf("\n");
#define MYNAME "XCSV"
#define ISSTOKEN(a,b) (strncmp(a,b, strlen(b)) == 0)
+static void *mkshort_handle;
+
/* a table of config file constants mapped to chars */
static
char_map_t xcsv_char_table[] = {
xcsv_wr_init(const char *fname, const char *args)
{
const char * p;
+ mkshort_handle = mkshort_new_handle();
/* if we don't have an internal style defined, we need to
* read it from a user-supplied style file, or die trying.
if (global_opts.synthesize_shortnames) {
p = get_option(args, "snlen");
if (p)
- setshort_length(atoi(p));
+ setshort_length(mkshort_handle, atoi(p));
p = get_option(args, "snwhite");
if (p)
- setshort_whitespace_ok(atoi(p));
+ setshort_whitespace_ok(mkshort_handle, atoi(p));
p = get_option(args, "snupper");
if (p)
- setshort_mustupper(atoi(p));
+ setshort_mustupper(mkshort_handle, atoi(p));
- setshort_badchars(xcsv_file.badchars);
+ setshort_badchars(mkshort_handle, xcsv_file.badchars);
}
}
#include "csv_util.h"
#define MYNAME "XMAPWPT"
+static void *mkshort_handle;
static void
xmapwpt_set_style()
/* set up mkshort */
if (global_opts.synthesize_shortnames) {
- setshort_length(32);
- setshort_whitespace_ok(0);
- setshort_badchars(xcsv_file.badchars);
+ setshort_length(mkshort_handle, 32);
+ setshort_whitespace_ok(mkshort_handle, 0);
+ setshort_badchars(mkshort_handle, xcsv_file.badchars);
}
}
static void
xmapwpt_wr_init(const char *fname, const char *args)
{
+ mkshort_handle = mkshort_new_handle();
+
xmapwpt_set_style();
xcsv_file.xcsvfp = fopen(fname, "w");